﻿using System.Linq;
using BenchmarkDotNet.Attributes;
using TiffLibrary.Compression;
using TiffLibrary.Tests.CompressionTests;

namespace TiffLibrary.Benchmarks.Compression
{
    [Config(typeof(Config))]
    public class DeflateDecompression
    {
        [Params(0, 1)]
        public int Index { get; set; }

        private TiffDecompressionContext context;
        private byte[] input;
        private byte[] output;

        [GlobalSetup]
        public void Setup()
        {
            var vars = DeflateCompressionTests.GetDeflateTestData().Skip(Index).First();

            int bytesPerRow = (int)vars[0];
            int height = (int)vars[1];
            input = (byte[])vars[2];
            output = (byte[])vars[3];

            context = new TiffDecompressionContext
            {
                ImageSize = new TiffSize(0, height),
                RequestedScanlines = height,
                BytesPerScanline = bytesPerRow,
            };
        }

        [Benchmark]
        public void Decompress()
        {
            DeflateCompressionAlgorithm compression = DeflateCompressionAlgorithm.Instance;
            compression.Decompress(context, input, output);
        }

    }
}
